
package com.wang.socket;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;


public class NettySocketChannelInitializer extends ChannelInitializer<SocketChannel> {


    // 字符串编码器和解码器
    private static final StringDecoder DECODER = new StringDecoder();
    private static final StringEncoder ENCODER = new StringEncoder();
    // 服务器端连接之后的执行器(自定义的类)
    private static final InBoundHandler SERVER_HANDLER = new InBoundHandler();

    /**
     * 初始化通道的具体执行方法
     */
    @Override
    public void initChannel(SocketChannel ch) {
        /*String delimiter = "_$";*/
        // 通道 Channel 设置
        ChannelPipeline pipeline = ch.pipeline();
        // 设置结尾分隔符
/*        pipeline.addLast(new DelimiterBasedFrameDecoder(1024, Unpooled.wrappedBuffer(delimiter.getBytes())));
        // 设置(字符串)编码器和解码器
        pipeline.addLast(DECODER);*/
        // pipeline.addLast(ENCODER);
        // 服务器端连接之后的执行器,接收到消息之后的业务处理
        pipeline.addLast(new CustomDecoder15());
        pipeline.addLast(SERVER_HANDLER);
    }
}